<?php
// 本类由系统自动生成，仅供测试用途
class PublicAction extends Action {
    public function login(){
		if(empty($_GET['action']) && $_GET['action'] != 'submit'){
			unset($_SESSION['AdminName']);
			unset($_SESSION['AdminId']);
			unset($_SESSION);
			$webname = C('CMSNAME');
			$data = array('login_url' => U('Public:login',array('action'=>'submit')),'img_url' => U('Public/verify'),);
			$this->assign('webname',$webname);
			$this->assign('data',$data);
			$this->assign('copyright','版权所有 &copy; 墨龙网络科技');
			$this->display('Common:login');
		}elseif(!empty($_GET['action']) && $_GET['action'] == 'submit'){
			Load('extend');
			$AdminName = $_POST['AdminName'];
			$Password  = md5(md5($_POST['Password']));
			if($_POST['verifyCode'] == '' || $_SESSION['verify'] != md5($_POST['verifyCode'])){
			   $this->assign("jumpUrl",U('Public/login'));
			   $this->error(" 验证码错误或不能为空！" );
			}
			if(!$AdminName || !$Password){
			   $this->assign("jumpUrl",U('Public/login'));
			   $this->error(" 请输入用户名和密码！" );
			}else{
				$Dbadmin = M('admin')->where("AdminName ='".$AdminName."' and Password = '".$Password."'")->find();
				if(!$Dbadmin){
				    $this->assign("jumpUrl",U('Public/login'));
				    $this->error(" 不存在此用户名或密码错误！" );
				}else{
					$_SESSION[C('USER_AUTH_KEY')] = 1;
					$_SESSION['AdminName']  = $AdminName;
					$_SESSION['AdminId']  = $Dbadmin['id'];
					$_SESSION['AdmingroupId']  = $Dbadmin['groupId'];
					$upadmin = M('admin');
					$upadmin-> where('id='.$Dbadmin['id'])-> setField(array('lastlogin','lastip'),array(date(),get_client_ip()));
				    $this->assign("jumpUrl",U('Index/index'));
				    $this->success(" 登入成功！" );
				}
			}
		}
    }
	
	public function logout(){
		unset($_SESSION['AdminName']);
		unset($_SESSION['AdminId']);
		unset($_SESSION);
		$this->assign("jumpUrl",U('Public:login'));
		$this->success('成功退出后台系统！');
	}
	
	//验证码生成
	public function verify(){
	   $type = isset($_GET['type'])?$_GET['type']:'gif';
	   import("ORG.Util.Image"); 
	   Image::buildImageVerify(4,1,$type,60,28); 
	}
}
?>